/*
 * 创建用户：mleo
 * 项目名称：demo
 * 模块名称：demo
 * 文件名称：APIOptional
 * 修改时间：2017/11/14 13:55:27
 * Copyright (c) 2017.
 */

package com.ichochy.api;

import com.ichochy.model.User;

import java.util.Optional;

public class APIOptional {

    public static void main(String[] args) {
        User user = null;
        Optional<User> optional = Optional.ofNullable(user);
        Optional<String> obj = optional.flatMap(value -> Optional.ofNullable(value.getUserName()));
        Optional<String> userName = optional.map(value -> value.getUserName());
        System.out.println(obj.orElse("hasNull"));
        System.out.println(userName.orElse("hasNull"));
        System.out.println(Optional.ofNullable(user).map(value->value.getUserName()).orElse("hasNull"));
    }



    private String getProperty(){
        return null;
    }

}
